<?php 
include_once('connection/connection.php');
include('header.php');
include('menu.php');
include('config.php');
$block=$_SESSION['form_id'];
$district=$_SESSION['district'];
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Source Sufficiency</title>
<style type="text/css">
.style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; color:#000000}
.style11 {font-size: 9px}
</style>
</head>
<body>
<?php
//$distId=401;
//$blockId=4183;
$distId= $district;//418;//$_REQUEST['distId'];
$blockId=$block;//4308;//$_REQUEST['blockId'];
//$villageId=366208;//$_REQUEST['villageId'];

//Select Data from lookup location table village wise
$sqlReport = "SELECT distinct block_id,village_id,block_name,village_name,census_village_code FROM tbl_lookup_location WHERE district_id='$distId' and block_id='$blockId' order by village_name";
//$sqlReport = "SELECT distinct block_id,village_id,block_name,village_name,census_village_code FROM tbl_lookup_location WHERE district_id='$distId' and block_id='$blockId' and village_id BETWEEN '345042' and '345060'";
$queryReport = mysql_query($sqlReport);

//query for find Population factor of corresponding district
$sqlPopFactor="select * from tbl_lookup_pop_factor where district_id='$distId'";
$queryPopFactor= mysql_query($sqlPopFactor);
$rowPopFactor=mysql_fetch_array($queryPopFactor);
$population_factor=$rowPopFactor['population_factor'];

//find lpcd for district
if(($distId == 389) || ($distId ==390) || ($distId == 391) || ($distId ==392) || ($distId ==398) || ($distId == 401) || ($distId == 402) || ($distId == 403) || ($distId == 404) || ($distId == 405) || ($distId == 406) || ($distId == 416))
{
	$lpcd=70;
}
else
{
	$lpcd=40;
}

?>
<div style="width:600px">
<table border="0" width="2420" cellspacing="0" cellpadding="0">
	<tr>
		<td width="2420" height="26" bgcolor="#E9E9E9">
		<p align="center"><span style="font-size: 9pt; font-weight: 700">
	  <font face="Verdana" color="#224568">Source Sufficiency Report</font></span></td>
	</tr>
	<tr>
	  <td bgcolor="#E9E9E9" height="26"><div align="center"><font face="Verdana" style="font-size: 9pt; font-weight: 700" color="#224568">&nbsp;</font></div></td>
  </tr>
	
	<tr>
	  <td><table border="1" width="2418" cellspacing="0" cellpadding="0" height="265" bordercolor="#FFFFFF" style="border: 1px solid #BBD1E8" bgcolor="#F9F9F9">
        <tr bgcolor="#C5D8EB">
          <td width="40" rowspan="3" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Name of Block</font></td>
          <td width="56" rowspan="3" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Name of revenue Village</font></td>
          <td width="170" rowspan="3" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Name of Dhani's (Habitation)</font></td>
          <td width="51" rowspan="3" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Census Code (2001)</font></td>
          <td colspan="4" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Population</font></td>
          <td width="71" rowspan="3" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Coverage (500 m or 30 min distance)</font></td>
          <td colspan="2" rowspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">SC/ST Mohallas</font></td>
          <td colspan="2" rowspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Water Supply Scheme</font></td>
          <td colspan="6" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Infrastructure of WSS (TW/HP)</font></td>
          <td width="90" rowspan="3" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Whether the sources are Excess (+) or Short (-) as compared to Departmental norms</font></td>
          <td colspan="3" rowspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Water Supply (lpcd)</font></td>
          <td width="81" rowspan="3" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Excess/Short (%)</span></font></td>
          <td colspan="3" rowspan="2" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Water Supply in SC/ST Habitation  (lpcd)</span></font></td>
          <td width="53" rowspan="3" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Duration of Water Supply (hrs / day)</span></font></td>
          <td colspan="2" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Water Quality </span></font> </td>
          <td width="87" rowspan="3" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Source Sustainanbility (% dependability of source)</span></font></td>
          <td colspan="3" rowspan="2" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Status of Household Security</span></font></td>
          <td width="123" rowspan="3" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">If short, specific measures proposed to meet the norms</span></font></td>
          <td width="71" rowspan="3" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Remarks</span></font></td>
        </tr>
        <tr bgcolor="#C5D8EB">
          <td colspan="2" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">VILLAGE</span></font></td>
          <td colspan="2" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">HABITATION</span></font></td>
          <td colspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">HP</font></td>
          <td colspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">TW</font></td>
          <td colspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">SP</font></td>
          <td colspan="2" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">PHED</span></font></td>
        </tr>
        <tr bgcolor="#C5D8EB">
          <td width="28" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">2001</span></font></td>
          <td width="28" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">2010</span></font></td>
          <td width="43" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">2001</span></font></td>
          <td width="46" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">2010</span></font></td>
          <td width="41" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">SC/ST Bastis</font></td>
          <td width="85" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">SC/ST infrastructure</font></td>
          <td width="62" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Type of Scheme eligible to be covered as per PHED Policy</font></td>
          <td width="62" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Type of Scheme vide which covered</font></td>
          <td width="58" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Required</font></td>
          <td width="41" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Actual</font> </td>
          <td width="60" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Required</font></td>
          <td width="39" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Actual</font></td>
          <td width="60" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Required</font></td>
          <td width="39" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Actual</font></td>
          <td width="40" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">As per norms</font></td>
          <td width="43" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Actual </font> </td>
          <td width="48" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Excess (+), Short (-)</font></td>
          <td width="75" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">As per norms</span></font></td>
          <td width="65" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Actual </span></font> </td>
          <td width="114" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Excess (+), Short (-)</span></font></td>
          <td width="36" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">P</span></font></td>
          <td width="29" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">NP</span></font></td>
          <td width="82" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Fully Secure >100% </span></font></td>
          <td width="115" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Secure 50% to 100% </span></font></td>
          <td width="112" align="center"><font face="Verdana" color="#000000"> <span style="font-size: 8.5pt">Critical Below 25% </span></font></td>
        </tr>
        <tr>
          <td height="26" align="center"><span class="style10">1</span></td>
          <td align="center"><span class="style10">2</span></td>
          <td align="center"><span class="style10">3</span></td>
          <td align="center"><span class="style10">4</span></td>
          <td width="28" align="center"><span class="style10">5</span></td>
          <td width="28" align="center"><span class="style10">6</span></td>
          <td width="43" align="center"><span class="style10">7</span></td>
          <td width="46" align="center"><span class="style10">8</span></td>
          <td align="center"><span class="style10">9</span></td>
          <td align="center"><span class="style10">10</span></td>
          <td align="center"><span class="style10">11</span></td>
          <td align="center"><span class="style10">12</span></td>
          <td align="center"><span class="style10">13</span></td>
          <td align="center"><span class="style10">14</span></td>
          <td align="center"><span class="style10">15</span></td>
          <td align="center"><span class="style10">16</span></td>
          <td align="center"><span class="style10">17</span></td>
          <td align="center"><span class="style10">18</span></td>
          <td align="center"><span class="style10">19</span></td>
          <td align="center"><span class="style10">20</span></td>
          <td align="center"><span class="style10">21</span></td>
          <td align="center"><span class="style10">22</span></td>
          <td align="center"><span class="style10">23</span></td>
          <td align="center"><span class="style10">24</span></td>
          <td align="center"><span class="style10">25</span></td>
          <td align="center"><span class="style10">26</span></td>
          <td align="center"><span class="style10">27</span></td>
          <td align="center"><span class="style10">28</span></td>
          <td align="center"><span class="style10">29</span></td>
          <td align="center"><span class="style10">30</span></td>
          <td align="center"><span class="style10">31</span></td>
          <td align="center"><span class="style10">32</span></td>
          <td align="center"><span class="style10">33</span></td>
          <td align="center"><span class="style10">34</span></td>
          <td align="center"><span class="style10">35</span></td>
          <td align="center"><span class="style10">36</span></td>
        </tr>
        <?php
			
			while($rowReport = mysql_fetch_array($queryReport)) 
			{
			$block_name=$rowReport['block_name'];
			$block_id=$rowReport['block_id'];
			$village_id=$rowReport['village_id'];
			$village_name=$rowReport['village_name'];
			$cen_vill_code=$rowReport['census_village_code'];
			$habitation_name=$rowReport['habitation_name'];
		
            $sqlScheme="SELECT type_scheme,duration_supply FROM tbl_dtls_q1_main main, tbl_dtls_q1_last last where main.block_id='$block_id' and main.village_id='$village_id' and main.id=last.loc_id";
			
               $queryScheme=mysql_query($sqlScheme);
               $rowScheme=mysql_fetch_array($queryScheme);
			   $duration=$rowScheme['duration_supply'];
			   $schemeDetails=$rowScheme['type_scheme'];
			           if($schemeDetails !='HP')
			              {
			          $sqlScheme1="SELECT * FROM tbl_dtls_q2_main where block_id='$block_id' and village_id='$village_id'";
				      $queryScheme1=mysql_query($sqlScheme1);
				      $num_rows = mysql_num_rows($queryScheme1);
                            if($num_rows > 0)
				               {
			                     $schemeDetails="HP";
                               }
			              }
//Query for finding RWSS scheme	
                      if($schemeDetails =='')
			              {	
					/* $qryRwssBlock="SELECT distinct block_id FROM tbl_dtls_q1_main where district_id='$distId'";
			         $queryRwssBlock=mysql_query($qryRwssBlock);	
					   	 while($rowRwssBlock=mysql_fetch_array($queryRwssBlock))
			                    {
								echo $rowRwssBlock['block_id'];
								}*/
			      $qryRwss="SELECT village_id FROM tbl_dtls_q1_main where block_id like '%$block%'";
				 
			         $queryRwss=mysql_query($qryRwss);
                          while($rowRwss=mysql_fetch_array($queryRwss))
			                    {
			                       //$rowRwss['village_id']."/".$village_id;
			            		   $vill = explode(",", $rowRwss['village_id']);
			                          if (in_array("$village_id", $vill)) 
				                          {
                                            $schemeDetails="RWSS";
                                          }
			                    }	
									
							}   

			
				$queryPopulationVillage="SELECT sum(total_population) FROM tbl_lookup_location WHERE block_id='$block_id' and village_id='$village_id' order by habitation_code";
				$ResultPopulationVillage = mysql_query($queryPopulationVillage);
				while($rowPopulationVillage = mysql_fetch_array($ResultPopulationVillage))
				{
				$village_population=$rowPopulationVillage['sum(total_population)'];
				}
			////// This is for column 16
		
			if($village_population <= 1500)
			{
				$column16="HP";
			}
			else if($village_population >=1501 and $village_population <= 4000)
			{
				$column16="P&T";
			}
			else if($village_population > 4000)
			{
				$column16="Piped";
			}
			//end of column 16
			 			 
			?>
        <tr valign="top">
          <td width="40" align="center"><span class="style10"><?php echo $block_name;?></span></td>
          <td width="56" align="center"><span class="style10"><?php echo $village_name;?></span></td>
          <td width="170" align="center"><span class="style10">&nbsp;</span></td>
          <td width="51" align="center"><span class="style10"><?php echo $cen_vill_code;?></span></td>
          <td width="28" align="center"><span class="style10"><?php echo $village_population;?></span></td>
          <td width="28" align="center"><span class="style10">
            <?php 
				echo round($village_population*$population_factor);
				?>
          </span> </td>
          <td width="43" align="center"><span class="style10">&nbsp;</span></td>
          <td width="46" align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10"><?php echo $column16;?></span></td>
          <td align="center"><span class="style10">
            <?php
				 echo $schemeDetails;
			?>
          </span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center">&nbsp;</td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">
            <?php
			
			    if($schemeDetails=="RWSS")
				{
				echo "EXCESS";
				}
				if(($column16=="HP" && $schemeDetails=="HP") || ($column16=="P&T" && $schemeDetails=="P&T") || ($column16=="P&T" && $schemeDetails=="TSS(P&T)") || ($column16=="Piped" && $schemeDetails=="Piped"))
				{
				echo "AS Per Norms";
				}
				if($column16=="HP" && ($schemeDetails=="P&T" || $schemeDetails=="Piped" || $schemeDetails=="TSS(P&T)"))
				{
				echo "EXCESS";
				}
				if($column16=="P&T" && $schemeDetails=="HP")
				{
				echo "SHORT";
				}
				if($column16=="P&T" && $schemeDetails=="Piped")
				{
				echo "EXCESS";
				}
				if($column16=="Piped" && ($schemeDetails=="HP" || $schemeDetails=="P&T" || $schemeDetails=="TSS(P&T)"))
				{
				echo "SHORT";
				}
				
				?>
          </span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">
            <?php if ($schemeDetails == 'HP'){ echo '24 Hrs';} else echo $duration;?>
          </span></td>
		  <td align="center"><span class="style10">
		    <?php
	
	$sqlSrc1="SELECT count(src.loc_id) FROM tbl_dtls_q3_water_source_detail src,tbl_dtls_q3_loc main where main.block_id='$block_id' and main.village_id='$village_id' and main.id=src.loc_id and functional_status='F' and src.para_tds <= 3000 and src.para_cl <= 1000 and src.para_f <= 3 and src.para_no3 <= 45 ";
		 
             $querySrc1=mysql_query($sqlSrc1);
			   
             $rowSrc1=mysql_fetch_row($querySrc1);
			 echo $rowSrc1[0];
			  // $tds=$rowSrc['para_tds'];
			  // $cl=$rowSrc['para_cl'];
			   //$f=$rowSrc['para_f'];
			  // $no3=$rowSrc['para_no3'];
			  // $bact=$rowSrc['bact'];
			  // if($tds > 3000 || $cl > 1000 || $f > 3 || $no3 > 45 || $bact=="yes")
			
		  
		  ?>
		  
		  </span></td>
          <td align="center"><span class="style10">
		  <?php
		
	 $sqlSrc="SELECT count(src.loc_id) FROM tbl_dtls_q3_water_source_detail src,tbl_dtls_q3_loc main where main.block_id='$block_id' and main.village_id='$village_id' and main.id=src.loc_id and functional_status='F' and ((para_tds >3000) or (para_cl >1000) or (para_f >3) or (para_no3 >45) )";
		
             $querySrc=mysql_query($sqlSrc);
			 $rowSrc=mysql_fetch_row($querySrc);
			 echo $rowSrc[0];
			  // $tds=$rowSrc['para_tds'];
			  // $cl=$rowSrc['para_cl'];
			   //$f=$rowSrc['para_f'];
			  // $no3=$rowSrc['para_no3'];
			  // $bact=$rowSrc['bact'];
			  // if($tds > 3000 || $cl > 1000 || $f > 3 || $no3 > 45 || $bact=="yes")
			
		  
		  ?>
		  </span></td>
         
          <td align="center"><span class="style10">
		  <?php
		  if($schemeDetails == "HP")
		  {
		   $sqlDuration="SELECT * FROM tbl_dtls_q2_main where block_id='$block_id' and village_id='$village_id'";
           $queryDuration=mysql_query($sqlDuration);
           $rowDuration=mysql_fetch_array($queryDuration);
		   $duration=$rowDuration['OA_operational_status'];
		   if($duration == 12)
		   {
		   echo "100%";
		   }elseif($duration == 9)
		    {
			echo "75%";
			}elseif($duration == 6)
			 {
			 echo"50%";
			 }else{
			     echo"0%";
			      }
		  }elseif($schemeDetails == "Piped" || $schemeDetails == "P&T" || $schemeDetails == "TSS(P&T)" || $schemeDetails == "RWSS")
		   {
		   $sqlStatus="SELECT * FROM tbl_dtls_q1_main main, tbl_dtls_q1_last last where main.block_id='$block_id' and main.village_id='$village_id' and main.id=last.loc_id";
           $queryStatus=mysql_query($sqlStatus);
           $rowStatus=mysql_fetch_array($queryStatus);
		   $Status=$rowStatus['current_status'];
		   if($Status == "operation")
		   {
		   echo "100%";
		   }elseif($Status == "defunct")
		    {
			echo "0%";
			}
		   }  
		  ?>		  
		  </span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
        </tr>
        <tr valign="top">
          <td width="40" height="25" align="center"><span class="style10">&nbsp;</span></td>
          <td width="56" align="center"><span class="style10">&nbsp;</span></td>
          <td width="170" align="center" valign="top"><table width="170" height="25" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#F9F9F9" style="border: 1px solid #BBD1E8">
              <?php 
			  
				$queryHabit="SELECT  habitation_name FROM tbl_lookup_location WHERE block_id='$block_id' and village_id='$village_id' order by habitation_code";
				$ResultHabit = mysql_query($queryHabit);
				
				while($rowHabit = mysql_fetch_array($ResultHabit))
				{
				?>
              <tr>
                <td height="23"><span class="style10"><?php echo $rowHabit['habitation_name'];?></span></td>
              </tr>
              <?php
				}
				?>
          </table></td>
          <td width="51" align="center">&nbsp;</td>
          <td width="28" align="center">&nbsp;</td>
          <td width="28" align="center">&nbsp;</td>
          <td colspan="3" align="center"><table border="1" cellspacing="0" cellpadding="0" width="164" bordercolor="#FFFFFF" style="border: 1px solid #BBD1E8" bgcolor="#F9F9F9">
              <?php 
				$queryPopulation="SELECT total_population,sc_population,st_population,habitation_code FROM tbl_lookup_location WHERE block_id='$block_id' and village_id='$village_id' order by habitation_code";
				$ResultPopulation = mysql_query($queryPopulation);
				
				while($rowPopulation = mysql_fetch_array($ResultPopulation)){
				//$habitation_code=$rowPopulation['habitation_code'];
				$total_population=$rowPopulation['total_population'];
			    $sc_population=$rowPopulation['sc_population'];
			    $st_population=$rowPopulation['st_population'];
			    $sc_st_population=$sc_population + $st_population;
			    $gen_population=$total_population - $sc_st_population;
				
				if($total_population!=0)
			{
				if(($sc_st_population/$total_population)>0.5)
				{
				  if(($sc_population/$sc_st_population)>0.5)
				  {
					$column13="SC";
				  }else{
				    $column13="ST";
				    }
				}
				else
				{
					$column13="GEN";
				}
			}
			else
			{
				if(sc_st_population>0.5)
				{
					$column13="SC/ST";
				}
				else
				{
					$column13="GEN";
				}
			} //end of column13
				
		
				?>
              <tr align="center" valign="top">
                <td width="41" height="23"><span class="style10"><?php echo $total_population;?></span></td>
                <td width="46"><span class="style10"><?php echo round($total_population*$population_factor);?></span></td>
                <td width="69"><span class="style10"><?php echo $column13;?></span></td>
              </tr>
              <?php
				}
				?>
            </table></td>
          <td align="center">&nbsp;</td>
          <td align="center">&nbsp;</td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center">&nbsp;</td>
          <td colspan="6" align="center" valign="top">
              <table border="1" cellspacing="0" cellpadding="0" width="308" bordercolor="#FFFFFF" style="border: 1px solid #BBD1E8" bgcolor="#F9F9F9">
                <?php 
			    $querySource="SELECT habitation_code,total_population,sc_population,st_population FROM tbl_lookup_location WHERE block_id='$block_id' and village_id='$village_id' order by habitation_code";
				$ResultSource = mysql_query($querySource);
				
				while($rowSource = mysql_fetch_array($ResultSource))
				{
			   $habitation_code=$rowSource['habitation_code'];
			   $total_population=$rowSource['total_population'];
			   $sc_population=$rowSource['sc_population'];
			   $st_population=$rowSource['st_population'];
			   $sc_st_population=$sc_population + $st_population;
			   $gen_population=$total_population - $sc_st_population;
				
				if($total_population!=0)
			{
				if(($sc_st_population/$total_population) > 0.5)
				{
					$column13="SC/ST";
				}
				else
				{
					$column13="GEN";
				}
			}
			else
			{
				if(sc_st_population > 0.5)
				{
					$column13="SC/ST";
				}
				else
				{
					$column13="GEN";
				}
			} //end of column13
	           $qrySource1="SELECT count(source_type) FROM tbl_dtls_q3_water_source_detail src,tbl_dtls_q3_water_source a where a.loc_id=src.loc_id and a.habitation_code='$habitation_code' and src.functional_status='F' and a.habitation_name=src.habitation_name and src.source_type like 'HpGovt%'";
               $recSource1=mysql_query($qrySource1);
               $rowSource1=mysql_fetch_row($recSource1);  
			   
			   $qrySourceTW="SELECT count(source_type) FROM tbl_dtls_q3_water_source_detail src,tbl_dtls_q3_water_source a where a.loc_id=src.loc_id and a.habitation_code='$habitation_code' and src.functional_status='F' and a.habitation_name=src.habitation_name and src.source_type like 'TW%'";
               $recSourceTW=mysql_query($qrySourceTW);
               $rowSourceTW=mysql_fetch_row($recSourceTW);   
               ?>
                <tr valign="top">
                  <td width="56" height="23" align="center"><span class="style10">
                <?php
				
				if(($column16 == "HP") && ($schemeDetails != "HP"))
				{
					echo "NA";
				}
				if(($column16 == "HP" || $column16 == "P&T" || $column16 == "Piped") && ($schemeDetails =="HP"))
				{
					if($column13 =="GEN")
					{
						echo ceil(($total_population*$population_factor)/250);
					}
					else
					{
						echo ceil(($total_population*$population_factor)/100);
					}
				}
				
				?>
                  </span></td>
                  <td align="center" width="42"><span class="style10"><?php echo $HPNos=$rowSource1[0];?></span></td>
                  <td align="center" width="59"><span class="style10">
			    <?php
				  if($schemeDetails != "HP")
				    {
					$qryYeild="SELECT a.yield_min FROM tbl_dtls_q1_sws a,tbl_dtls_q1_oh b where a.loc_id=b.loc_id and b.habit_code='$habitation_code' and a.source='Tube-Well'";
                    $recYeild=mysql_query($qryYeild);
                    $rowYeild=mysql_fetch_row($recYeild);
					$minYeild=$rowYeild[0];
					$x=$minYeild*8*1000;
					if($x == 0)
					{
					echo "0";
					}else{
					echo ceil(($total_population*$population_factor*$lpcd)/$x);
					}
				    }
				?></span></td>
                  <td align="center" width="38"><span class="style10"><?php echo $rowSourceTW[0];?></span></td>
                  <td align="center" width="62">&nbsp;</td>
                  <td align="center" width="36">&nbsp;</td>
                </tr>
                <?php
				}
				
				?>
              </table></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td colspan="7" align="center"><table border="1" cellspacing="0" cellpadding="0" width="478" bordercolor="#FFFFFF" style="border: 1px solid #BBD1E8" bgcolor="#F9F9F9">
              <?php 
				
				$queryHPCount="SELECT  habitation_code,total_population,sc_population,st_population FROM tbl_lookup_location WHERE block_id='$block_id' and village_id='$village_id' order by habitation_code";
				$ResultHPCount= mysql_query($queryHPCount);
				$i=1;
				
				while($rowHPCount = mysql_fetch_array($ResultHPCount))
				{
				$i;
				$habit_idHPCount=$rowHPCount['habitation_code'];
				$total_populationWater=$rowHPCount['total_population'];
				$sc_populationWater=$rowHPCount['sc_population'];
			    $st_populationWater=$rowHPCount['st_population'];
			    $sc_st_populationWater=$sc_populationWater + $st_populationWater;
			    $gen_populationWater=$total_populationWater - $sc_st_populationWater;
				if($total_populationWater!=0)
			 {
				if(($sc_st_populationWater/$total_populationWater)>0.5)
				{
					$column131="SC/ST";
				}
				else
				{
					$column131="GEN";
				}
			}
			else
			{
				if(sc_st_populationWater>0.5)
				{
					$column131="SC/ST";
				}
				else
				{
					$column131="GEN";
				}
			} //end of column13
			
	  /*  echo    $qrysrcTyp="SELECT src.type_habit FROM tbl_dtls_q3_water_source_detail src,tbl_dtls_q3_water_source a where a.loc_id=src.loc_id and a.habitation_code='$habit_idHPCount'";
                $recsrcTyp=mysql_query($qrysrcTyp);
                $rowsrcTyp=mysql_fetch_row($recsrcTyp);  
		  echo  $srcTyp=$rowsrcTyp[0]; */
				
				$qryHPCount="SELECT count(source_type) FROM tbl_dtls_q3_water_source_detail src,tbl_dtls_q3_water_source a where a.loc_id=src.loc_id and a.habitation_code='$habit_idHPCount' and src.functional_status='F' and a.habitation_name=src.habitation_name and src.source_type like 'HpGovt%'";
               $recHPCount=mysql_query($qryHPCount);
               $rowHPCount=mysql_fetch_row($recHPCount);  
			   $HPCount=$rowHPCount[0];
			 				
				$Current_populaionWater=$total_populationWater*$population_factor;
			    $queryWater="SELECT b.water_supply FROM tbl_dtls_q1_last b,tbl_dtls_q1_oh a where a.loc_id=b.loc_id and a.habit_code='$habit_idHPCount'";
				                   $ResultWater = mysql_query($queryWater);
				                   $rowWater = mysql_fetch_row($ResultWater);
								    if($schemeDetails == "HP")
		                             {
								      $Supply_data=round(($HPCount*10*1000)/$Current_populaionWater);
									 }elseif($schemeDetails != "HP" && $i == 1)
									    { 
										 if($schemeDetails == "RWSS")
										   {
										 $Supply_data="NP";
										   }else{
									         $Supply_data=round((($rowWater[0]+($HPCount*10))*1000)/$Current_populaionWater);
											    }
									    }elseif($schemeDetails != "HP" && $i != 1)
									    {
								      $Supply_data=round(($HPCount*10*1000)/$Current_populaionWater);
									    }
				?>
              <tr align="center" valign="top">
                <td width="37" height="23"><span class="style10"><?php echo $lpcd;?></span></td>
                <td width="44"><span class="style10"><?php echo $Supply_data;?></span></td>
                <td width="48"><span class="style10">
                  <?php
								  if($Supply_data != "NP")
								  {
								   if($lpcd < $Supply_data)
								   {
								   echo "+";
								   }else{
								   echo "-";
								   }
								  }else{
								   echo "";
								       }
								   ?>
                </span></td>
                <td width="79"><span class="style10">
				<?php 
				  if($Supply_data != "NP")
								  {
				echo ceil((($Supply_data-$lpcd)*100)/$lpcd); 
                                  }else{
								    echo "";
								       }				
				?></span></td>
                <td width="76"><span class="style10">
                  <?php 
								   if($column131=="SC/ST")
								   {
								    echo $lpcd;
								   }
								   ?>
                </span></td>
                <td width="65"><span class="style10">
                  <?php  
								   if($column131=="SC/ST")
								   {
								    echo $Supply_data;
								   } 
								   ?>
                </span></td>
                <td width="113"><span class="style10">
                  <?php
								   if($column131=="SC/ST" && $Supply_data != "NP")
								   {
								   if($lpcd < $Supply_data)
								   {
								   echo "+";
								   }else{
								   echo "-";
								   }
								   }else{
								   echo "";
								        }
								   ?>
                </span></td>
              </tr>
              <?php
			  $i++;
				}
				?>
            </table></td>
          <td align="center"><span class="style10"></span></td>
          <td align="center"><span class="style10"></span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
          <td colspan="3" align="center"><table border="1" cellspacing="0" cellpadding="0" width="313" bordercolor="#FFFFFF" style="border: 1px solid #BBD1E8" bgcolor="#F9F9F9">
		  <?php
			
				$queryHPCount="SELECT  habitation_code,total_population,sc_population,st_population FROM tbl_lookup_location WHERE block_id='$block_id' and village_id='$village_id' order by habitation_code";
				$ResultHPCount= mysql_query($queryHPCount);
				$i=1;
				
				while($rowHPCount = mysql_fetch_array($ResultHPCount))
				{
				$i;
				$habit_idHPCount=$rowHPCount['habitation_code'];
				$total_populationWater=$rowHPCount['total_population'];
				$sc_populationWater=$rowHPCount['sc_population'];
			    $st_populationWater=$rowHPCount['st_population'];
			    $sc_st_populationWater=$sc_populationWater + $st_populationWater;
			    $gen_populationWater=$total_populationWater - $sc_st_populationWater;
				if($total_populationWater!=0)
			 {
				if(($sc_st_populationWater/$total_populationWater)>0.5)
				{
					$column131="SC/ST";
				}
				else
				{
					$column131="GEN";
				}
			}
			else
			{
				if(sc_st_populationWater>0.5)
				{
					$column131="SC/ST";
				}
				else
				{
					$column131="GEN";
				}
			} //end of column13
			
	  /*  echo    $qrysrcTyp="SELECT src.type_habit FROM tbl_dtls_q3_water_source_detail src,tbl_dtls_q3_water_source a where a.loc_id=src.loc_id and a.habitation_code='$habit_idHPCount'";
                $recsrcTyp=mysql_query($qrysrcTyp);
                $rowsrcTyp=mysql_fetch_row($recsrcTyp);  
		  echo  $srcTyp=$rowsrcTyp[0]; */
				
				$qryHPCount="SELECT count(source_type) FROM tbl_dtls_q3_water_source_detail src,tbl_dtls_q3_water_source a where a.loc_id=src.loc_id and a.habitation_code='$habit_idHPCount' and src.functional_status='F' and a.habitation_name=src.habitation_name and src.source_type like 'HpGovt%'";
               $recHPCount=mysql_query($qryHPCount);
               $rowHPCount=mysql_fetch_row($recHPCount);  
			   $HPCount=$rowHPCount[0];
			 				
				$Current_populaionWater=$total_populationWater*$population_factor;
			    $queryWater="SELECT b.water_supply FROM tbl_dtls_q1_last b,tbl_dtls_q1_oh a where a.loc_id=b.loc_id and a.habit_code='$habit_idHPCount'";
				                   $ResultWater = mysql_query($queryWater);
				                   $rowWater = mysql_fetch_row($ResultWater);
								    if($schemeDetails == "HP")
		                             {
								      $Supply_data=ceil(($HPCount*10*1000)/$Current_populaionWater);
									 }elseif($schemeDetails != "HP" && $i == 1)
									    { 
										 if($schemeDetails == "RWSS")
										   {
										 $Supply_data="NP";
										   }else{
									         $Supply_data=ceil((($rowWater[0]+($HPCount*10))*1000)/$Current_populaionWater);
											    }
									    }elseif($schemeDetails != "HP" && $i != 1)
									    {
								      $Supply_data=ceil(($HPCount*10*1000)/$Current_populaionWater);
									    }
										
										
										$symbol=($Supply_data*100)/$lpcd;
										
				?>
								
			  
		 
		  <tr valign="top"><td width="80" height="23" align="center"><span class="style10"><?php 
		  //echo $Supply_data;
		  if($Supply_data == "NP")
		  {
		  echo "";
		  }elseif($symbol >= 100){ echo '*'; }else{ echo '';}?></span></td>
		  <td width="115" align="center"><span class="style10"><?php 
		//  echo $Supply_data;
		  if($Supply_data == "NP")
		  {
		  echo "";
		  }elseif(($symbol >50 || $symbol ==50) && ($symbol <100)){ echo '+';}else{ echo '';}?></span></td>
		  <td width="110" align="center"><span class="style10"><?php 
		  //echo $Supply_data;
		    if($Supply_data == "NP")
		    {
		     echo "-";
		    }elseif($symbol < 26)
		     {
		     echo '-';
		     }else{ 
			 echo '';
			     }
		 
		  ?></span></td>
		  </tr>
		  <?php	
		  $i++;  
		  }
		  ?>
		  </table></td>
          <td align="center"><span class="style10">&nbsp;</span></td>
			 <td align="center"><span class="style10">&nbsp;</span></td>
        </tr>
        <?php } ?>
         <tr bgcolor="#FFFFCC">
          <td height="26" colspan="36" align="left"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Note:-<br><br><b>Field:-Status of Household Security</b><br><p>&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;Fully secured habitation(>100%)<p>&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;secured habitation(50% to 100%)<p>&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;Critical habitation(<25%)<br><br><b>Field:-Water Supply (lpcd)</b><br><br>&nbsp;&nbsp;&nbsp;&nbsp;NP&nbsp;&nbsp;&nbsp;&nbsp;The data is not provided by PHED and hence you may refer RWSS report for details.</font></td>
        </tr>
      </table></td>
	</tr>
</table>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>